package com.gln.bloger.dao.impl;

import java.util.List;

import org.hibernate.Hibernate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gln.bloger.pojos.Category;

public class TestCategoryDaoImpl extends HibernateDaoSupport{
	@SuppressWarnings("unchecked")
	public List<Category> loadAll(){
		List<Category> categorys = (List<Category>)getHibernateTemplate().loadAll(Category.class);
		for(Category c: categorys){
		    Hibernate.initialize(c.getWebsite());
		    System.out.print(c);
		}
		return categorys;
	}
	
	public Category get(String id){
		Category category = (Category)getHibernateTemplate().get(Category.class, id);
		    System.out.print(category);
		    Hibernate.initialize(category.getWebsite());
		    System.out.print(category.getWebsite());
		return category;
	}

	public static void main(String [] args){
		ApplicationContext ctx=new  
		FileSystemXmlApplicationContext("webRoot/WEB-INF/config/spring/testbeans.xml");
	    TestCategoryDaoImpl cdao = (TestCategoryDaoImpl)ctx.getBean("testCategoryDao");
	    @SuppressWarnings("unused")
		Category category = cdao.get("2c9083ad1adca6ca011adca770360002");
//	    List<Comment> comments = cdao.loadAll();
	}
}
//2c9083ad1adca6ca011adca770360002 category id

//2c9083ad1a9a182d011a9a19175c0001 comment id